package com.sys.SysTanks.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sys.common.annotation.Log;
import com.sys.common.core.controller.BaseController;
import com.sys.common.core.domain.AjaxResult;
import com.sys.common.enums.BusinessType;
import com.sys.SysTanks.domain.SysTanksArea;
import com.sys.SysTanks.service.ISysTanksAreaService;
import com.sys.common.utils.poi.ExcelUtil;
import com.sys.common.core.page.TableDataInfo;

/**
 * 养殖桶区域Controller
 * 
 * @author ruoyi
 * @date 2025-09-08
 */
@RestController
@RequestMapping("/SysTanksArea/SysTanksArea")
public class SysTanksAreaController extends BaseController
{
    @Autowired
    private ISysTanksAreaService sysTanksAreaService;

    /**
     * 查询养殖桶区域列表
     */
    @PreAuthorize("@ss.hasPermi('SysTanksArea:SysTanksArea:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTanksArea sysTanksArea)
    {
        startPage();
        List<SysTanksArea> list = sysTanksAreaService.selectSysTanksAreaList(sysTanksArea);
        return getDataTable(list);
    }

    /**
     * 导出养殖桶区域列表
     */
    @PreAuthorize("@ss.hasPermi('SysTanksArea:SysTanksArea:export')")
    @Log(title = "养殖桶区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysTanksArea sysTanksArea)
    {
        List<SysTanksArea> list = sysTanksAreaService.selectSysTanksAreaList(sysTanksArea);
        ExcelUtil<SysTanksArea> util = new ExcelUtil<SysTanksArea>(SysTanksArea.class);
        util.exportExcel(response, list, "养殖桶区域数据");
    }

    /**
     * 获取养殖桶区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('SysTanksArea:SysTanksArea:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysTanksAreaService.selectSysTanksAreaById(id));
    }

    /**
     * 新增养殖桶区域
     */
    @PreAuthorize("@ss.hasPermi('SysTanksArea:SysTanksArea:add')")
    @Log(title = "养殖桶区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTanksArea sysTanksArea)
    {
        return toAjax(sysTanksAreaService.insertSysTanksArea(sysTanksArea));
    }

    /**
     * 修改养殖桶区域
     */
    @PreAuthorize("@ss.hasPermi('SysTanksArea:SysTanksArea:edit')")
    @Log(title = "养殖桶区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysTanksArea sysTanksArea)
    {
        // 情况1：前端传了 ids 数组 -> 批量删除
//        if (sysTanksArea.getIds() != null && !sysTanksArea.getIds().isEmpty()) {
//            sysTanksAreaService.updateSysTanksArea(sysTanksArea.getIds());
//            return AjaxResult.success();
//        }
        // 情况2：只传了单个 id -> 单个更新（原有逻辑）
        return toAjax(sysTanksAreaService.updateSysTanksArea(sysTanksArea));
    }

    /**
     * 删除养殖桶区域
     */
    @PreAuthorize("@ss.hasPermi('SysTanksArea:SysTanksArea:remove')")
    @Log(title = "养殖桶区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysTanksAreaService.deleteSysTanksAreaByIds(ids));
    }
}
